package com.hdoit.kylin.logical.studentManager.dao.impl;

import java.util.List;

import org.springframework.stereotype.Component;

import com.hdoit.kylin.logical.studentManager.dao.IWritePaperDao;
import com.hdoit.kylin.logical.studentManager.model.WritePaper;
import com.hdoit.kylin.logical.viewmodel.postgraduate.WritePaperSearch;
import com.tennetcn.common.dao.base.IFinderExpression;
import com.tennetcn.common.dao.base.impl.SuperDao;
import com.tennetcn.common.enums.OrderEnum;
import com.tennetcn.common.message.PagerModel;
import com.tennetcn.common.utils.FinderExpressionFactory;

/**
 * @author anshengqiang
 * @email
 * @createtime 2017年08月01日 18:04:14
 * @comment
 */
@Component
public class WritePaperDaoImpl extends SuperDao<WritePaper> implements IWritePaperDao {
	
	@Override
	public int queryCount(WritePaperSearch search) {
		IFinderExpression finderExpression = FinderExpressionFactory.createExpression();
		finderExpression.select("count(DISTINCT writePaper.id) as count")
				.from(WritePaper.class, "writePaper")
				.setMainTableAlias("writePaper");
		return queryCount(finderExpression, search);
	}
	
	@Override
	public List<WritePaper> queryList(WritePaperSearch search, PagerModel pagerModel) {
		IFinderExpression finderExpression = FinderExpressionFactory.createExpression();
		finderExpression
				.select("writePaper.*")
				.from(WritePaper.class, "writePaper")
				.addOrder("paperDate", OrderEnum.desc);
		if(pagerModel==null){
			return queryList(finderExpression,search); 
		}
		return queryList(finderExpression,search,pagerModel);
	}
}